# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=rauc
pkgver=1.10.1
pkgrel=1
pkgdesc="Safe and secure software updates for embedded Linux"
arch=(loong64 x86_64)
url="https://rauc.io"
license=(LGPL2.1)
depends=(
  gcc-libs
  glibc
  libnl
  openssl
  sh
)
makedepends=(
  curl
  dbus
  glib2
  json-glib
  python
  systemd
  util-linux
)
checkdepends=(squashfs-tools)
optdepends=(
  'casync: for casync conversion support'
  'cryptsetup: for disk encryption support'
  'dosfstools: for creating and checking FAT filesystems'
  'e2fsprogs: for creating and checking ext2/3/4 filesystems'
  'efibootmgr: for interacting with EFI boot manager'
  'grub: for GRUB support'
  'mtd-utils: for interacting with MTD devices'
  'squashfs-tools: for creating and inspecting bundles'
  'uboot-tools: for u-boot support'
)
source=(https://github.com/rauc/rauc/releases/download/v$pkgver/$pkgname-$pkgver.tar.xz{,.asc})
sha512sums=('794a1a517c9a9eacf7466710054f88fc48bf57e34cb460f202f62ca976777054c0faf74dd045164ea29977aa8f5d9d268f5154621b51642898ffafc831c75bbb'
            'SKIP')
b2sums=('3cdaa88886e0d4f97623939af06a0a90de1a166535ff1cdaf523938a1778bfdd24049387886732d1a13c0d94a43d66f73d9328cc005beb3a73f33b3afda49b22'
        'SKIP')
validpgpkeys=("977843FD5C3EBF76BAD4008EA58CC53DBF05E090")  # Jan Lübbe <jlu@pengutronix.de>

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --libexecdir=/usr/lib
    --enable-gpt
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  make
}

check() {
  make -k check -C $pkgname-$pkgver
}

package() {
  depends+=(
    curl libcurl.so
    glib2 lib{gobject,gio,glib}-2.0.so
    json-glib libjson-glib-1.0.so
    util-linux-libs libfdisk.so
  )

  make DESTDIR="$pkgdir/" install -C $pkgname-$pkgver
  install -vdm 755 "$pkgdir/etc/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/contrib/{grub.conf,uboot.sh} -t "$pkgdir/usr/share/doc/$pkgname/"
}
